
<template>
  <div class="home">
    <Header />
    <Banner />
    <div class="con">
      <div class="cistern">
        <p>很多 Web 开发人员对 HTML 的代码规范知之甚少</p>
        <p>很多 Web 开发人员对 HTML 的代码规范知之甚少</p>
        <p>很多 Web 开发人员对 HTML 的代码规范知之甚少</p>
        <p>很多 Web 开发人员对 HTML 的代码规范知之甚少</p>
        <p>很多 Web 开发人员对 HTML 的代码规范知之甚少</p>
      </div>
    </div>
  </div>
</template>

<script>
import Header from "../components/header.vue";
import Banner from "../components/banner.vue";
export default {
  name: "home",
  components: {
    Banner,
    Header
  },
  data() {
    return {
      tabList: "",
      acitveIndex: 0,
      articleList: "",
      lists: [
        {
          link: "/details",
          text: "怎么添加阴影"
        },
        {
          link: "/details",
          text: "怎么添加阴影"
        },
        {
          link: "/details",
          text: "怎么添加阴影"
        },
      ]
    };
  },
  async asyncData({ $axios }) {
    return await $axios
      .get(`/article/list/${encodeURI("热门推荐")}`)
      .then(({ data }) => {
        let tabList = ["热门推荐"];
        data.forEach(element => {
          tabList.push(element.type);
        });
        // 数组去重
        tabList = Array.from(new Set(tabList));

        // 反转数据
        data.reverse();

        return {
          tabList: tabList,
          articleList: data
        };
      })
      .catch(err => {
        console.log(err);
      });
  },
  methods: {
    // 点击tab切换，获取数据
    getDataList(item, index) {
      // 设置当前tab标红
      this.acitveIndex = index;
      // 获取数据
      this.$axios
        .get(`/article/list/${encodeURI(item)}`)
        .then(({ data }) => {
          // 反转数据
          data.reverse();
          this.articleList = data;
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>

<style scoped lang="less">
@import "../assets/css/base.less";

.home {
  .con {
    padding: 50px 0;
    .cistern {
      max-width: 1000px;
      margin: 0 auto;
      p {
        font-size: 16px;
        color: @ch;
        margin-top: 10px;
      }
    }
  }
}
</style>
